import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TestAction_2 {
    public static void main(String[] args) {
        //两个按钮实现同一个监听
        //开始   停止
        //e.getActionCommand()获得按钮信息，点击按钮时打印出start --- stop
        Frame frame = new Frame("开始--停止");
        Button button1 = new Button("start");
        Button button2 = new Button("stop");
        button2.setActionCommand("button2-stop");//setActionCommand可以设置按钮信息
        MyMonitor myMonitor = new MyMonitor();
        //添加
        button1.addActionListener(myMonitor);
        button2.addActionListener(myMonitor);
        frame.add(button1,BorderLayout.WEST);
        frame.add(button2,BorderLayout.EAST);
        frame.pack();
        frame.setVisible(true);
    }
}
class MyMonitor implements ActionListener{
    //e.getActionCommand()获得按钮信息
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("按钮被点击了msg:"+e.getActionCommand());
        if (e.getActionCommand().equals("start")){
            System.out.println("判断出start。游戏开始");
        }else {
            System.out.println("This is stop");
        }
    }
}